<!-- 我的弹窗 -->

<template>
  <WebShow class="PatrolReport-MyRecord marginBottom">
    <EasyScroll class="row10">
      <div v-for="item in one.list" :key="item.pointId" class="flex">
        <div class="flex0">{{ CORE.timeStr(item.arriveTime) || '-' }}</div>

        <div class="flex1">
          <span>{{ item.pointName }}</span>

          <ShowImage :one="imgIOT" :bind="item.pointId" :ref="`photo-${item.pointId}`" v-show="false" />
          <BtnText v-if="!CORE.isEmpty(item.files)" title="查看照片" small @click="toPreview(item)" />

          <div>
            <ShowStatus :one="item" bind="pointStatus" :dict="DICT.TRACK_STATUS" noLabel />
          </div>
        </div>
      </div>
    </EasyScroll>
  </WebShow>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'MyRecord',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb(), CORE.mixInfo()],

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    /**
     * 图片映射
     */
    imgIOT() {
      const CACHE = CORE.CACHE[this.MAP.CACHE]
      const imgIOT = {}
      this.one.list.forEach((item) => {
        imgIOT[item.pointId] = item.files.map((id) => CACHE[id])
      })
      return imgIOT
    },
  },

  /**
   * 监听属性 (深度 deep 首次 immediate)
   */
  watch: {
    /**
     * 监听信息就绪
     */
    readyInfo(ready) {
      ready && this.openPreview()
    },
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 点击预览
     */
    toPreview(item) {
      this.infoParam.pointId = item.pointId
      this.infoParam.ids = item.files
      this.startInfo()
    },

    /**
     * 打开预览
     */
    openPreview() {
      const refPoint = this.$refs[`photo-${this.infoParam.pointId}`]
      const showImage = (CORE.isArray(refPoint) ? (refPoint || [])[0] : refPoint) || {}
      showImage.preview()
    },
  },
}
</script>

<style lang="scss">
@import './index.scss';
</style>
